package com.gec.listener;

import com.mysql.cj.jdbc.AbandonedConnectionCleanupThread;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.sql.DriverManager;
import java.sql.SQLException;

@WebListener
public class JDBCListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
    }


    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        try {
            while (DriverManager.getDrivers().hasMoreElements()) {
                DriverManager.deregisterDriver(DriverManager.getDrivers().nextElement());
            }
            AbandonedConnectionCleanupThread.checkedShutdown();
        } catch (SQLException ignore) {
        }
        System.exit(0);
    }
}
